var API_URL = 'https://2016.bookgo.com.cn/';
// var API_URL = 'http://192.168.31.153/project/public/';
var IMG_URL = 'https://2016.bookgo.com.cn/static/wxapp/reading_images/';

function fetchApi(type, params, method) {
    return new Promise(function (resolve, reject) {
        wx.request({
            url: API_URL + type,
            data: params,
            method: method,
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            success: resolve,
            fail: reject
        })
    });
}

function getData(type, params, callback) {
    fetchApi(type, params, 'GET').then(function (result) {
        typeof callback == "function" && callback(result);
    })
}
function postData(type, params, callback) {
    fetchApi(type, params, 'POST').then(function (result) {
        typeof callback == "function" && callback(result);
    })
}

    

module.exports = {
    API_URL,
    IMG_URL,
    getData,
    postData,
}